********************************************************************************
********"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*****
********************************************************************************

********************************************************************************
********************************************************************************
********************************2019 AND 2015***********************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global regcommands ", compact pool(2) absorb(bankid2 borrowerid#time) vce(cluster bankid2)"


**#Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(e12 e13 exlnassets excashas)
keep if _merge==3
drop _merge

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
run RO_tdummies 2015 1

keep bankid borrowerid time e12 e13 excashas exlnassets lncrefin lncdisbur dT7

**#Bookmark (input)
append using $inputdirectory/INB_core2019temp, keep(bankid borrowerid time e12 e13 excashas exlnassets lncrefin lncdisbur dT7)

run RO_tdintera 1 "excashas exlnassets e12 e13"

gen post=((time>=tm(2015m1)&time<=tm(2015m6))|(time>=tm(2019m9)))
gen p2019=(time>=tm(2019m3))
foreach var of varlist excashas exlnassets e12 e13 {
gen post`var'=post*`var'
}

gen bankid2=bankid
replace bankid2=bankid+99999 if time>=tm(2019m3)
foreach var of varlist dT7e13 dT7e12 dT7exlnasset dT7excashas {
gen `var'p2019=`var'*p2019
}
foreach var of varlist poste13 poste12 postexlnasset postexcashas {
gen `var'p2019=`var'*p2019
}
gen lncrefinp2019=lncrefin*p2019

winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

**#Bookmark (output - columns 1-2-3-4)
cd $outputdirectory
est clear
reghdfe $y poste12 poste12p2019 poste13 postexlnassets postexcashas lncrefin $regcommands
est save TAB4_C1234
reghdfe $y poste12 poste12p2019 poste13 postexlnassets postexlnassetsp2019 postexcashas postexcashasp2019 lncrefin lncrefinp2019 $regcommands
est save TAB4_C1234, append
reghdfe $y poste12 poste12p2019 poste13 poste13p2019  postexlnassets postexlnassetsp2019 postexcashas postexcashasp2019 lncrefin lncrefinp2019 $regcommands
est save TAB4_C1234, append
reghdfe $y dT7e12 dT7e12p2019 dT7e13 dT7e13p2019 dT7exlnassets dT7exlnassetsp2019 dT7excashas dT7excashasp2019 lncrefin lncrefinp2019 $regcommands
est save TAB4_C1234, append
cd ..

